/**
 * 
 */
package soa.security.web.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;

import soa.security.domain.LdapTree;
import soa.security.mgr.service.GroupMgrService;
import soa.security.mgr.service.PositionMgrService;
import soa.security.mgr.service.TreeMgrService;
import soa.security.web.export.LdapTreeJsonFormatExport;
import v1.web.WebUtils;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @author Cre.Gu
 *
 */
public class TreeAction extends ActionSupport {
	private static final long serialVersionUID = -3744501870551671261L;

	@Resource
	private TreeMgrService treeMgrService;
	@Resource
	private PositionMgrService positionMgrService;
	@Resource
	private GroupMgrService groupMgrService;

	private String organizationId;
	private String departmentId;
	private String positionId;
	private String dnp;

	/**
	 * 地区树
	 * 
	 * @return String
	 * 
	 * @author Cre.Gu at 2015年5月29日
	 */
	public String regionTree() {
		List<LdapTree> trees = treeMgrService.regionTree();
		LdapTreeJsonFormatExport content = new LdapTreeJsonFormatExport(trees);

		return WebUtils.writeJson(ServletActionContext.getResponse(),
				content.toString());
	}

	/**
	 * 机构树
	 * 
	 * @return String
	 * 
	 * @author Cre.Gu at 2015年5月29日
	 */
	public String organizationTree() {
		List<LdapTree> trees = treeMgrService.organizationTree();
		LdapTreeJsonFormatExport content = new LdapTreeJsonFormatExport(trees);

		return WebUtils.writeJson(ServletActionContext.getResponse(),
				content.toString());
	}

	/**
	 * 部门树
	 * 
	 * @return String
	 * 
	 * @author Cre.Gu at 2015年5月29日
	 */
	public String departmentTree() {
		List<LdapTree> trees = treeMgrService.departmentTree();
		LdapTreeJsonFormatExport content = new LdapTreeJsonFormatExport(trees);

		return WebUtils.writeJson(ServletActionContext.getResponse(),
				content.toString());
	}

	/**
	 * 账号下的对应人员树，指定机构下的人员树
	 * 
	 * @return String
	 * 
	 * @author Cre.Gu at 2015年5月29日
	 */
	public String personInOneOrgTree() {
		List<LdapTree> trees = treeMgrService
				.personInOneOrgTree(organizationId);
		LdapTreeJsonFormatExport content = new LdapTreeJsonFormatExport(trees);

		return WebUtils.writeJson(ServletActionContext.getResponse(),
				content.toString());
	}

	/**
	 * 人员调入页面的部门树，指定机构下的部门树，过滤指定部门
	 * 
	 * @return String
	 * 
	 * @author Cre.Gu at 2015年5月29日
	 */
	public String personInTree() {
		List<LdapTree> trees = treeMgrService.deptInOneOrgTree(organizationId);
		LdapTreeJsonFormatExport content = new LdapTreeJsonFormatExport(trees);

		return WebUtils.writeJson(ServletActionContext.getResponse(),
				content.toString());
	}

	public String getOrganizationId() {
		return organizationId;
	}

	public void setOrganizationId(String organizationId) {
		this.organizationId = organizationId;
	}

	public String getDepartmentId() {
		return departmentId;
	}

	public void setDepartmentId(String departmentId) {
		this.departmentId = departmentId;
	}

	public String getPositionId() {
		return positionId;
	}

	public void setPositionId(String positionId) {
		this.positionId = positionId;
	}

	public String getDnp() {
		return dnp;
	}

	public void setDnp(String dnp) {
		this.dnp = dnp;
	}
}
